import * as types from './actionTypes';

import {ToastAndroid} from 'react-native';
import getStorage from '../Common/storage';

var storage = getStorage().getInstance();
const search = (keyword) => {
  return (dispatch, getStore) => {


    dispatch({
       type: types.Search
    });

   //ToastAndroid.show("正在搜索",ToastAndroid.SHORT);

    let ticket;
    storage.load({
       key: 'ticket',
    }).then( ret => {
      ticket = ret.Ticket;
    //  alert(ticket);
      fetch('http://42.159.143.17:6080/alfresco/s/slingshot/search?term='+keyword+'&alf_ticket='+ticket,{
           method: 'GET'
          })
      .then(res => {
        if (res.status >= 400) {




        }



        return res.json();
      })
      .then(data => {
      //  alert( data.items);
        dispatch({
           type: types.SearchCompelete,
           date:data.items
             });

      })
      .catch(error => {
        console.log('ERRORR');
      });

    }).catch( err => {
    })





    //  alert(email);dsds   sadsa
	 }
 }


export default {
   search
}
